package com.smart.seven.aop.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 性能监视横切代码
 *
 * @author junrui.wang
 * @create 2018/7/24
 */
public class PerformanceHandle implements InvocationHandler { //实现InvocationHandler
    //目标业务类
    private Object target;

    public PerformanceHandle(Object target) {
        this.target = target;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //开始对方法进行性能监视
        PerformanceMonitor.begin(target.getClass().getName() + "." + method.getName());

        //通过反射方法调用业务类的目标方法
        Object object = method.invoke(target, args);

        //结束对方法的性能监视
        PerformanceMonitor.end();

        return object;
    }
}
